﻿using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Xml;
using System.Net;


namespace UI_Layer
{
    class Parser
    {
        public Parser() { }

        public string[] getBooking(int booking_number)
        {
            String[] booking = new String[5];
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                string requesturl = "http://localhost/Service.svc/readBooking/" + booking_number;
                HttpWebRequest request = WebRequest.Create(requesturl) as HttpWebRequest;
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                xmlDoc.Load(response.GetResponseStream());
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
                      
            XmlNode root = xmlDoc.FirstChild;
            
            if (root.HasChildNodes)
            {
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    booking[i]=root.ChildNodes[i].InnerText;
                }
            }
            
            return booking;
        }

        public string getBookingNO(string url)
        {
            string bookingNO = "";
            XmlDocument xmlDoc = new XmlDocument();

            try
            {                
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                xmlDoc.Load(response.GetResponseStream());
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            XmlNode root = xmlDoc.FirstChild;
            if (root.HasChildNodes)
            {
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    bookingNO = root.ChildNodes[i].InnerText;
                }
            }
            return bookingNO;
        }
    }
}
